﻿/*
Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/

CKEDITOR.editorConfig = function( config )
{
	config.toolbar = 'RTFToolbar';
	config.toolbar_RTFToolbar =
	[
		/*['Source','-','Save','NewPage','Preview','-','Templates'],*/
		['Preview','Templates'],
		['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'],
		['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
		['Form','Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton','HiddenField'],
		['BidiLtr','BidiRtl'],
		'/',
		['Bold','Italic','Underline','Strike','-','Subscript','Superscript'],
		['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'],
		['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
		['Link','Unlink','Anchor'],
		['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak'],
		'/',
		['Styles','Format','Font','FontSize'],
		['TextColor','BGColor'],
		['Maximize','ShowBlocks','-','Source','-','About']
	];

	config.font_names='宋体/宋体;黑体/黑体;仿宋/仿宋_GB2312;楷体/楷体_GB2312;隶书/隶书;幼圆/幼圆;微软雅黑/微软雅黑;'+ config.font_names;

	CKEDITOR.on('dialogDefinition',function(ev){
		var dialogName = ev.data.name;
		var dialogDefinition = ev.data.definition;
		if ( dialogName == 'image'){
			var infoTab = dialogDefinition.getContents('info');
			dialogDefinition.onCancel=cancelUpload;
			infoTab.add({type:'button',label:'选择',id:'selectimg',onClick:rtfSelectImage},'browse');
		}else if(dialogName == 'flash'){
			var infoTab = dialogDefinition.getContents('info');
			dialogDefinition.onCancel=cancelUpload;
			infoTab.add({type:'button',label:'选择',id:'selectflash',onClick:rtfSelectFlash},'browse');
		}
	});
};
//选择图片
function rtfSelectImage(){
	var params={pdir:'document','punid':resource.UNID,act:'actRTFImage'};
	Selector.show({datasource:'image://','value':params,valueOk:rtfSelectImageOk});
}
//选择图片确定
function rtfSelectImageOk(tvroot){
	var imageUrl=tvroot.targetFiles[0].value;
	var dlg=CKEDITOR.dialog.getCurrent();
	var imgUrl=dlg.getContentElement('info','txtUrl');
	imgUrl.setValue(imageUrl);
}
//选择Flash
function rtfSelectFlash(){
	var params={pdir:'document','punid':resource.UNID,act:'actRTFFlash'};
	Selector.show({datasource:'image://','value':params,valueOk:rtfSelectFlashOk,selectDialogParams:{title:'选择Flash动画文件','filter':'Flash动画|*.swf'}});
}
//选择Flash确定
function rtfSelectFlashOk(tvroot){
	var flashUrl=tvroot.targetFiles[0].value;
	var dlg=CKEDITOR.dialog.getCurrent();
	var txtSrc=dlg.getContentElement('info','src');
	txtSrc.setValue(flashUrl);
}
//取消：删除上传的内容
function cancelUpload(){
	var dlg=CKEDITOR.dialog.getCurrent();
	var txt=dlg.getContentElement('info','src');
	if(txt==undefined || txt==null) txt=dlg.getContentElement('info','txtUrl');
	if(txt==undefined || txt==null) return;
	var url=txt.getValue();
	if(url.indexOf('download?target=')>=0){
		url=url.replace(/download/ig,'dispatch') + '&fx=accessory&action=4';
		var ajaxRequest = new AjaxRequest({ unique: true, async: false });
		ajaxRequest.request(url);
		var jsonResult = ajaxRequest.jsonResult;
		if (jsonResult == undefined || jsonResult == null) {
			//alert('删除文件时发生错误：无法发送请求！');
			return;
		}
		if (jsonResult.status < 0) {
			//alert('删除文件时发生错误：' + jsonResult.message);
			return;
		}
	}
}